/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.仅执行一次字符串交换能否使两个字符串相等;

import java.util.LinkedList;

public class Main {
    public boolean areAlmostEqual(String s1, String s2) {
        char[] chars1=s1.toCharArray();
        char[] chars2=s2.toCharArray();
        //首先最多两个字符不同
        //如果只有一处也不行
        int count=0;
        LinkedList<Character> data1=new LinkedList<>();
        LinkedList<Character> data2=new LinkedList<>();
        for (int i = 0; i < chars1.length; i++) {
            if (chars1[i]!=chars2[i])
             {
                 count++;
                data1.addLast(chars1[i]);
                data2.addFirst(chars2[i]);
            }
        }
        if (count!=2&&count!=0) return false;
        //交换后的字符串相等
        while (!data1.isEmpty())
        {
            if (data1.pollLast()!=data2.pollLast())
                return false;
        }
        return true;
    }
}
